let navsecond = document.querySelector('.nav-second-body')
ajax({
  method: "get",
  url: "stage-api/website/getProductMenuInfo",
  success: function(res){
    console.log(res)
    for (let i = 0; i < res.data.length; i++) {
      if (i == 4) {
        continue;
      }else if(i == 6){
        continue;
      }else{
         navsecond.innerHTML += `<li class="nav-second-item" onclick="detail('${res.data[i].productId}')">
                                <div class="navsec-bod">
                                  <img src="${res.data[i].menuIcon.split("?")[0]}">
                                  <div>${res.data[i].productName}</div>
                                </div>
                              </li>`
      }
    }
  }
})

function detail(productId) {
      location.href = `product.html?productId=${productId}`
    }

let form = document.getElementById('demoForm');
        let errorElements = document.querySelectorAll('.error');

        form.addEventListener('submit', (e) => {
            e.preventDefault();
            let isValid = true;

            // 清除所有错误提示
            errorElements.forEach(error => error.style.display = 'none');

            // 验证必填字段
            let requiredFields = [
                { id: 'product', errorId: 'productError' },
                { id: 'name', errorId: 'nameError' },
                { id: 'phone', errorId: 'phoneError' }
            ];

            requiredFields.forEach(field => {
                let input = document.getElementById(field.id);
                let error = document.getElementById(field.errorId);
                
                if (!input.value.trim()) {
                    error.style.display = 'block';
                    isValid = false;
                }
            });

            // 验证电话号码格式
            let phoneInput = document.getElementById('phone');
            let phoneRegex = /^1[3-9]\d{9}$/;
            if (phoneInput.value && !phoneRegex.test(phoneInput.value)) {
                document.getElementById('phoneError').style.display = 'block';
                isValid = false;
            }

            // 验证邮箱格式
            let emailInput = document.getElementById('email');
            if (emailInput.value) {
                let emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
                if (!emailRegex.test(emailInput.value)) {
                    emailInput.nextElementSibling.style.display = 'block';
                    isValid = false;
                }
            }

            if (isValid) {
                // 这里可以添加提交逻辑
                let formData = {
                    product: document.getElementById('product').value,
                    name: document.getElementById('name').value,
                    phone: document.getElementById('phone').value,
                    company: document.getElementById('company').value,
                    email: document.getElementById('email').value,
                    address: document.getElementById('address').value,
                    notes: document.getElementById('notes').value
                };

                console.log('提交数据:', formData);
                alert('提交成功！我们的工作人员会尽快与您联系。');
                form.reset();
            }
        });